package cn.itcast.solrj;

import cn.itcast.solrj.cn.itcast.solrj.pojo.Student;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class SolrjCreatTest {
    @Test
    public void TestSolrj() throws IOException, SolrServerException {
        //和solr服务器建立连接
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");

        //创建doucument
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id","10010");
        document.addField("title","滴答滴爱啊");
        document.addField("price",488898783);

        solrServer.add(document);
        solrServer.commit();
    }
    @Test
    public void TestUpdateSolrj() throws IOException, SolrServerException {
        //和solr服务器建立连接
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");

        //创建doucument
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id","10010");
        document.addField("title","id不变其他随意");
        document.addField("price",488898783);

        solrServer.add(document);
        solrServer.commit();
    }
    @Test
    public void TestUpdateSolrjBean() throws IOException, SolrServerException {
        //和solr服务器建立连接
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");

        Student student = new Student("12325","我好气啊",6858968L);

        solrServer.addBean(student);
        solrServer.commit();
    }
}
